<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="btn" uri="http://www.dsdl.com/dev/jsp/btn" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%@include file="../base/base.jspf" %>
<div class="layui-fluid">
    <div class="layui-card">
        <form class="layui-form"
              lay-filter="association-associationPage-search" id="association-associationPage-search">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">协会名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="assName" placeholder="请输入协会名称" autocomplete="off"
                                   class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">负责人</label>
                        <div class="layui-input-block">
                            <input type="text" name="assPrincipal" placeholder="请输入负责人" autocomplete="off"
                                   class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">负责人号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="assPrincipalMobile" placeholder="请输入负责人号码" autocomplete="off"
                                   class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" type="button" lay-submit lay-filter="association-associationPage-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>

                </div>
            </div>
        </form>

        <div class="layui-card-body">

            <script type="text/html" id="toolbar-associationListPage-association">
                <div class="layui-btn-container">
                    <btn:btn btnStr="associationAdd">
                        <button class="layui-btn" lay-event="add">新增</button>
                    </btn:btn>
                </div>
            </script>
            <table id="association-associationList-page" lay-filter="association-associationList-page"></table>
            <script type="text/html" id="table-associationPage-btn">
                <btn:btn btnStr="associationEdit">
                    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit"><i
                            class="layui-icon layui-icon-edit"></i>编辑</a>
                </btn:btn>
                <%--<btn:btn btnStr="resetassociationPsw">--%>
                    <%--<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="resetPsw"><i--%>
                            <%--class="layui-icon layui-icon-refresh"></i>重置密码</a>--%>
                <%--</btn:btn>--%>

                {{# if(d.assStt == 0 ){ }}
                <btn:btn btnStr="associationDisable">
                    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="disable"><i
                            class="layui-icon layui-icon-face-cry"></i>禁用</a>
                </btn:btn>
                {{# } }}
                {{# if(d.assStt == 1 ){ }}
                <btn:btn btnStr="associationEnable">
                    <a class="layui-btn layui-btn layui-btn-xs" lay-event="enable"><i
                            class="layui-icon layui-icon-face-smile"></i>启用</a>
                </btn:btn>
                {{# } }}

              <%--  <btn:btn btnStr="associationDelete">
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                            class="layui-icon layui-icon-delete"></i>删除</a>
                </btn:btn>--%>
            </script>
        </div>
    </div>
</div>



<script type="text/javascript">
    layui.config({
        base: "${ctx}/static/framework/layuiadmin/" //静态资源所在路径
    }).extend({
        index: "lib/index" //主入口模块
    }).use(["index", "table", "form"], function () {
        var table = layui.table, form = layui.form;
        table.render({
            elem: "#association-associationList-page",
            url: "${ctx}/association/getAssociationList",
            method: "post",
            toolbar: "#toolbar-associationListPage-association",
            defaultToolbar: ["filter", "print","exports"],
            height: "full-125",//自己根据表格上方和下方的高度减去对应数值，保证侧边无滚动条即可
            cols: [[{
                field: "assId",
                title: "ID",
                width: 70,
                sort: true
            }, {
                field: "assName",
                title: "协会名称",
                width: 150,
            }, {
                field: "assPrincipal",
                title: "负责人",
                width: 150,
            },{
                field: "assPrincipalMobile",
                title: "负责人号码",
                width: 150,
            }, {
                field: "mebStt",
                title: "状态",
                templet: function (data) {
                   if(data.assStt == 0){
                       return "<span style='color: green;'>启用</span>";
                   }else{
                       return "<span style='color: red;'>禁用</span>";
                   }
                }
            },  {
                field: "assCreateTime",
                title: "添加时间",
                width: 200,
                sort: true,
                templet: function (data) {
                    var dt = parseToDate(data.assCreateTime);
                    return dt.format("yyyy-MM-dd");
                }
            },{
                title: "操作",
                width: 300,
                align: "center",
                fixed: "right",
                toolbar: "#table-associationPage-btn"
            }]],
            page: true,
            limit: 20,
            limits: [20, 50, 100],
            text: {
                none: "暂无相关数据"
            }
        });
        form.on("submit(association-associationPage-search)", function (data) {
            table.reload("association-associationList-page", {
                where: data.field,
                page: {curr: 1}
            });
        });

        //显示大图片
        showBigImage = function (e) {
            console.log(e)
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true, //点击阴影关闭
                area: [$(e).width + 'px', $(e).height + 'px'], //宽高
                content: "<img src=" + $(e).attr('src') + " />"
            });
        }

      /*  $.ajax({//获取会员总人数
            async: true,
            url: "${ctx}/association/getassociationCount",
            type: "get",
            success: function (data) {
               $("#associationCount").html("会员总人数："+data);
            }
        });*/

        table.on("tool(association-associationList-page)", function (obj) {
            var data = obj.data;
            if (obj.event == "del") {
                layer.confirm("您确定要删除该协会吗？", {
                    icon: 3,
                    title: "提示",
                    btn: ["确定", "取消"] //按钮
                }, function (index) {
                    tip_index = load();
                    $.ajax({
                        async: true,
                        url: "${ctx}/association/associationDelete",
                        type: "post",
                        dataType: "json",
                        data: {
                            id: data.assId
                        },
                        success: function (data1) {
                            layer.close(tip_index);
                            if (data1.result) {
                                success(data1.info);
                                table.reload("association-associationList-page");
                            } else {
                                error(data1.info);
                            }
                        }
                    });
                    layer.close(index);
                }, function (index) {
                    layer.close(index);
                });
            } else if (obj.event == "resetPsw") {
                layer.confirm("您确定重置该协会密码吗？", {
                    icon: 3,
                    title: "提示",
                    btn: ["确定", "取消"] //按钮
                }, function (index) {
                    tip_index = load();
                    $.ajax({
                        async: true,
                        url: "${ctx}/association/resetPassword?id="+data.assId,
                        type: "get",
                        dataType: "json",
                        success: function (data1) {
                            layer.close(tip_index);
                            layer.msg(data1.info, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            });
                          //  table.reload("association-associationList-page");
                        }
                    });
                    layer.close(index);
                }, function (index) {
                    layer.close(index);
                });
            }   else if (obj.event == "disable") {
                layer.confirm("您确定要禁用该协会吗？", {
                    icon: 3,
                    title: "提示",
                    btn: ["确定", "取消"] //按钮
                }, function (index) {
                    tip_index = load();
                    $.ajax({
                        async: true,
                        url: "${ctx}/association/updateState",
                        type: "post",
                        dataType: "json",
                        data: {
                            id: data.assId,
                            stt:1
                        },
                        success: function (data1) {
                            layer.close(tip_index);
                            layer.msg(data1.info, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            });
                            table.reload("association-associationList-page");
                        }
                    });
                    layer.close(index);
                }, function (index) {
                    layer.close(index);
                });
            } else if (obj.event == "enable") {
                layer.confirm("您确定要启用该协会吗？", {
                    icon: 3,
                    title: "提示",
                    btn: ["确定", "取消"] //按钮
                }, function (index) {
                    tip_index = load();
                    $.ajax({
                        async: true,
                        url: "${ctx}/association/updateState",
                        type: "post",
                        dataType: "json",
                        data: {
                            id: data.assId,
                            stt:0
                        },
                        success: function (data1) {
                            layer.close(tip_index);
                            layer.msg(data1.info, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            });
                            table.reload("association-associationList-page");

                        }
                    });
                    layer.close(index);
                }, function (index) {
                    layer.close(index);
                });
            }else if (obj.event == "edit") {
                layer.open({
                    type: 2,
                    title: "协会编辑",
                    content: "${ctx}/association/associationSubmitPage?id="+data.assId,
                    offset: "t",
                    maxmin: true,
                    area: ["800px", "600px"],
                    btn: ["确定", "取消"],
                    yes: function (index, layero) {
                        var iframeWindow = window["layui-layer-iframe" + index];
                        iframeWindow.getIds(); //获取已勾选节点
                        layero.find("iframe").contents().find("#association-front-submit").trigger("click");
                    }
                });
            }
        });
        table.on("toolbar(association-associationList-page)", function (obj) {
            if (obj.event == "add") {
                layer.open({
                    type: 2,
                    title: "协会添加",
                    content: "${ctx}/association/associationSubmitPage",
                    offset: "t",
                    maxmin: true,
                    area: ["800px", "600px"],
                    btn: ["确定", "取消"],
                    yes: function (index, layero) {
                        var iframeWindow = window["layui-layer-iframe" + index];
                        iframeWindow.getIds(); //获取已勾选节点
                        layero.find("iframe").contents().find("#association-front-submit").trigger("click");
                    }
                });
            }
        });
    });
</script>

<style type="text/css">
    .layui-table-cell {
        height: auto;
        line-height: 28px;
    }
</style>